from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from webdriver_manager.chrome import ChromeDriverManager

#获取文本

ChromeIns=ChromeDriverManager().install()
driver=webdriver.Chrome(service=Service(ChromeIns))

driver.get("https://www.baidu.com")

text = driver.find_element(By.CSS_SELECTOR, "#hotsearch-content-wrapper > li:nth-child(5) > a > span.title-content-title").get_attribute("class")
print(text)
assert text== "title-content-title"
#特殊情况：元素属性值不等于文本信息，id和type和value与class都是属性，其中的内容都是属性值而不是
#文本内容。

#获取属性值：
text = driver.find_element(By.CSS_SELECTOR, "#chat-submit-button").get_attribute("id")
print(text)

text = driver.find_element(By.CSS_SELECTOR, "#chat-submit-button").text
print(text)

#获取标题和url
title=driver.title
url=driver.current_url
print(title)
print(url)

driver.quit()